home *** CD-ROM | disk | FTP | other *** search
/ BMUG PD-ROM 1996 Fall / BMUG Fall'96 PD-ROM.iso / Education / Math / MathPad 2.4 / Examples / interpolation < prev    next >
Text File  |  1994-05-30  |  434b  |  22 lines

  1. -- Solve for coefficients of a polynomial that goes through n data points.
  2.  
  3. include ":incl:solver"
  4.  
  5. data = read(xydata)
  6. plot data[1:n]
  7.  
  8. x[i]=data[i,1] dim[n] -- separate x and y
  9. y[i]=data[i,2] dim[n]
  10.  
  11. f(x)[j] = x^(j-1)  -- polynomial
  12.  
  13. -- construct matrix using x data points
  14. A[i,j] = f(x[i])[j] dim[n,n]
  15.  
  16. -- solve for coeffs that give y points
  17. c:=solve(A,y):
  18. c:{0.797,3.863,-0.715,0.057,-0.002,0.000}
  19.  
  20. n=6
  21. plot sum((c*f(X))[i],i,1,n)
  22.